<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>冒泡排序</title>
	</head>
	<body>
		<script type="text/javascript">
			var arr=[98,31,24,33,42]
			console.log("待排序数组："+arr);
			//2、冒泡排序：外循环控制趟数，内循环控制每趟比较次数
			for (var i=1; i<=arr.length; i++) {
				for (var j=0;j<arr.length-i;j++) {
					//比较相邻两数，交换位置
					if (arr[j]>=arr[j+1]) {
						var a=arr[j];
						arr[j]=arr[j+1];
						arr[j+1]=a;
						
					} 
					
				}
				
			}
			console.log("排序后的数组："+arr)
		</script>
	</body>
</html>
